package com.platform.comm.common.batch.processor;


import com.platform.vo.ImportDto;
import com.platform.comm.common.batch.ComBatchContext;
import org.springframework.batch.item.ItemProcessor;

import javax.validation.constraints.NotNull;

/**
 * description: 通用数据校验类
 *
 * @author lx
 */
public class ComImportDataValidationProcessor implements ItemProcessor<ImportDto, ImportDto> {

    private ComBatchContext context;
    public ComImportDataValidationProcessor(ComBatchContext context) {
        this.context = context;
    }

    @Override
    public ImportDto process( @NotNull ImportDto item) {
        try {
            if (!item.isFlag()) {
                return item;
            }
            context.validateImport(item);
        } catch (Exception ex) {
            item.setFlag(false);
            item.setErrMsg(ex.getMessage());
        }
        return item;
    }
}
